<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/ordermaker/pages/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form layui-form-pane" action="">

    <div class="layui-inline">
        <label class="layui-form-label">日期范围</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="test6" placeholder=" - ">
        </div>
    </div>
</form>

<script src="/ordermaker/pages/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;

        //日期范围
        laydate.render({
            elem: '#test6'
            ,range: true
        });

        //监听提交
        form.on('submit(useradd)', function(data){
            layui.jquery.ajax({
                url: "/ordermaker/admin/user/add",
                type: 'post',//method请求方式，get或者post
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                xhrFields:{
                    withCredentials:true
                },
                dataType: 'json',//预期服务器返回的数据类型
                data: data.field,//表格数据序列化
                success: function (res) {//res为相应体,function为回调函数
                    if(res.erro===1){
                        layer.alert('该邮箱已存在数据库!', {icon: 5});
                    }
                    return;
                },
                error: function (res) {
                    console.log(res)
                    layer.alert('操作失败！！！', {icon: 5});
                }
            });

            layer.alert("增加成功", {icon: 6}, function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });

            return false;
        });
    });
</script>
</body>
</html>